package pro1;

/**
 * @version 1.0
 * @since:
 * @ClassName:CountTest
 * @author: Li Jiahui
 * @date: 2021-03-29 10:10
 * 编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打印出来。
 */
public class CountTest {
    public static void main(String[] args) {
        //1.声明引用数据类型指向引用数据对象
        String s1 = new String("ABCD123!@#$%ab");
        char[] bArr =s1.toCharArray();
        //2.定义大写字母、小写字母、数字、其它字符个数的变量
        int bigCount=0, smallCount=0, numCount=0, otherCount=0;
        //3.定义大写字母、小写字母、数字、其它字符个数的String
        StringBuilder bigLetter = new StringBuilder();
        StringBuilder smallLetter = new StringBuilder();
        StringBuilder numLetter = new StringBuilder();
        StringBuilder otherLetter =new StringBuilder();
        //4.分类字符类型
        for ( int ia = 0; ia <s1.length();ia++ ){
            if (bArr[ia]>=48 && bArr[ia]<=59){
                numCount++;
                numLetter.append(bArr[ia]);
                /*numLetter.concat(bArr[ia]);*/
            }else if(bArr[ia] >=65 && bArr[ia] <=90){
                bigCount++;
                bigLetter.append(bArr[ia]);
            }else if(bArr[ia] >=97 && bArr[ia] <=122){
                smallCount++;
                smallLetter.append(bArr[ia]);
            }else{
                otherCount++;
                otherLetter.append(bArr[ia]);
            }
            //System.out.println("barr[" +ia + "]=" + bArr[ia]);
        }
        //5.对分类后的字符类型，输出打印
        System.out.println(s1.toString()+"中的大写字母有："+ bigCount +"个，分别是：" +bigLetter.toString());
        System.out.println(s1.toString()+"中的小写字母有："+ smallCount +"个，分别是：" +smallLetter.toString());
        System.out.println(s1.toString()+"中的数字有："+ numCount +"个，分别是：" +numLetter.toString());
        System.out.println(s1.toString()+"中的其他有："+ otherCount +"个，分别是：" +otherLetter.toString());
    }
}
